<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实验4</title>
</head>
<body>
    <script>
        //189000950 顾啟思
        //第一题
        let a1, b1, c1 = [1, 2, 3, ];//应该用数组解构数组
        console.log(a1, b1, c1);

        let [a2, b2, c2] = [1, 2, 3, ];//数组解构赋值
        console.log(a2, b2, c2);

        let [a3, b3, c3] = [1, , 3, ];//数组第二个为空 b3解构不成功 为undefined
        console.log(a3, b3, c3);

        let [a4, b4] = [1];//数组只有一个元素 默认给a4 b4解构不成功 为undefined
        console.log(a4, b4);

        let {y:a5, b5} = {X: 1,y: 2};//解构是按照属性名称 不按照顺序
        console.log(a5, b5);

        let {a6, b6} = 123;//解构布尔值，数值，字符串将得到undefined
        console.log(a6, b6);

        //第二题
        let set  = new Set();
        set.add(1);//添加1
        set.add(2);//添加2
        set.add(3);//添加3
        set.delete(2);//删除2

        let i = set.values();
        console.log(i.next());//value:1 done:false 还未完结
        console.log(i.next());//value:3 done:false 还未完结
        console.log(i.next());//value:undefined done:ture 完结

        //第三题
        let map = new Map();
        map.set(1, "a");
        map.set(2, "b");
        map.set(3, "c");
        map.set(4, "d");
        //遍历Map
        for (let i = 1; i <= map.size; i++){
            console.log(map.get(i));
        }

        map.forEach(function(value, key){
            console.log(value);
        });

        for(let v of map.values()){
            console.log(v);
        }

        for(var prop in map){
            console.log(prop);//Map集合是键值对形式存储的
        }

        //第四题
        let arr1 = [1, 2, 3];

        let arr2 = arr1;
        console.log(arr1==arr2);

        let arr3 = [...arr1];
        console.log(arr1==arr3);
        //扩展运算符就是三个点“...”，就是将实现了Iterator 接口的对象中
        //的每个元素都一个个的迭代并取出来变成单独的被使用。

        //第五题
        let arr4 = [1, 2, 3];
        arr4.forEach(function(v, k){
            console.log(v);
        });
        //第五题改写
        arr4.forEach((v, k) => console.log(v));//简化回调函数

        //第6题
        Array.of(1, 2, 3).filter(i => i > 1).forEach(i => console.log(i));
        let fib = n => n > 1 ? fib(n - 1) + fib(n - 2) : n;

        //第七题
        class Animal {
            // 构造函数
            constructor(name, age) {
                this.name = name;
                this.age = age;
            }
            shout() {
                console.log('咆哮！');
            }
        }

        class Dog extends Animal {
            constructor(name,age) {
                // super就代表 父类的构造函数
                super(name,age)
            }
            eat() {
                console.log('吃饭！');
            }
        }
        let obj1 = new Animal('金毛',5);
        console.log(obj1);
        console.log(obj1.shout);
    </script>
</body>
</html>